//package com.china.produce.config.datasource;
//
//import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.SqlSessionTemplate;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.EnvironmentAware;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.env.Environment;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//import org.springframework.transaction.PlatformTransactionManager;
//import javax.sql.DataSource;
//
///**
// * @ClassName
// * @Author niujie
// * @Version
// * @Description
// * @CreateTime 2023/2/7
// */
//@Configuration
//@MapperScan(basePackages = {"com.china.produce.mapper.studyProd"}, sqlSessionFactoryRef = "prodSessionFactory")
//public class StudyProdDataSource implements EnvironmentAware {
//
//    static String MAPPER_READ_LOCATION;
//
//    @Bean(name = "prodDataSource")
//    @ConfigurationProperties(value = "spring.datasource.druid.study-prod")
//    public DataSource prodDataSource() {
//        return DruidDataSourceBuilder.create().build();
//    }
//
//    @Bean(name = "prodSessionFactory")
//    public SqlSessionFactory prodSessionFactory(@Qualifier("prodDataSource") DataSource dataSource) throws Exception {
//        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
//        bean.setDataSource(dataSource);
//        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MAPPER_READ_LOCATION));
//
//        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
//        configuration.setMapUnderscoreToCamelCase(true);
//        bean.setConfiguration(configuration);
//
//        return bean.getObject();
//    }
//
//    @Bean(name = "prodTransactionManager")
//    public DataSourceTransactionManager prodTransactionManager(@Qualifier("prodDataSource") DataSource dataSource) {
//        return new DataSourceTransactionManager(dataSource);
//    }
//
//    @Bean(name = "prodSessionTemplate")
//    public SqlSessionTemplate prodSessionTemplate(@Qualifier("prodSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
//        return new SqlSessionTemplate(sqlSessionFactory);
//    }
//
//    //创建prod数据源的事务管理器，否则在需要发生回滚时@Transactional会报错
//    @Bean(name = "prodManager")
//    public PlatformTransactionManager txManager(@Qualifier("prodDataSource") DataSource dataSource) {
//        return new DataSourceTransactionManager(dataSource);
//    }
//
//    @Override
//    public void setEnvironment(Environment environment) {
//
//        MAPPER_READ_LOCATION = environment.getProperty("mybatis.study-prod.mapper-locations");
//    }
//}
